require "Common/define"
require "Logic/Config"
require "Common/functions"

RedDotsGuildGiftHandler ={}
local this = RedDotsGuildGiftHandler

function RedDotsGuildGiftHandler.init()
    CloseEvent(Config.EventType.GuildGiftRefresh,this.update)
    ListenEvent(Config.EventType.GuildGiftRefresh,this.update)
    return this
end

function RedDotsGuildGiftHandler.getFlag()
    local isLeader = logicMgr.GuildManager.isChairman()
    local waitReceiveList = logicMgr.GuildManager.GetWaitToRecvGiftList()
    if #waitReceiveList > 0 then
        return Config.RedDotsFlagState.Needful
    else
        if isLeader then
            local waitPayList = logicMgr.GuildManager.GetWaitToPayGiftList()
            if #waitPayList > 0 then
                return Config.RedDotsFlagState.Needful
            end
        end
    end
    return Config.RedDotsFlagState.None
end

function RedDotsGuildGiftHandler.update()
    RedDotsManager.addBroadcast(Config.RedDotsType.GuildGift);
end